<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.opensourcebolivia.navidar.modelo.Navidar" %>
<%@ page import="com.opensourcebolivia.navidar.service.NavidarDAO" %>

<!DOCTYPE html>


<%@page import="java.util.ArrayList"%>

<html>
	<head>
		<title>Navidares</title>
		<link rel="stylesheet" type="text/css" href="css/main.css"/>
		<meta charset="utf-8"> 
	</head>
	<body>
<%
NavidarDAO dao = NavidarDAO.INSTANCE;

UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();

String url = userService.createLoginURL(request.getRequestURI());
String urlLinktext = "Login";
List<Navidar> navidares = new ArrayList<Navidar>();
            
if (user != null){
    url = userService.createLogoutURL(request.getRequestURI());
    urlLinktext = "Logout";
    navidares = dao.lista();
}
%>
<jsp:include page="menu.jsp"></jsp:include>
	<div style="width: 100%;">
		<div class="line"></div>
		<div class="topLine">
			<div style="float: left;"><img src="images/todo.png" /></div>
			<div style="float: left;" class="headline">Navidar</div>
			<div style="float: right;"><a href="<%=url%>"><%=urlLinktext%></a> <%=(user==null? "" : user.getNickname())%></div>
		</div>
	</div>

<div style="clear: both;"/>	
Total <%= navidares.size() %>  encargados.

<table>
  <tr>
      <th>Organizacion </th>
      <th>Lugar Recepcion Cajas</th>      
    </tr>

<% for (Navidar navidar : navidares) {%>
<tr> 
<td>
<%=navidar.getOrganizador()%>
</td>
<td>
<%=navidar.getLugarRecepcionCajas()%>
</td>
<td>
<a class="done" href="/doneNavidar?id=<%=navidar.getId()%>" >Eliminar</a>
</td>
</tr> 
<%}
%>
</table>


<hr />

<div class="main">

<div class="headline">Nuevo Navidar</div>

<% if (user != null){ %> 

<form action="/newNavidar" method="post" accept-charset="utf-8">
	<table>
		<tr>
			<td><label for="organizador">Organizacion</label></td>
			<td><input type="text" name="organizador" id="organizador" size="65"/></td>
		</tr>
		<tr>
			<td><label for="lugarRecepcionCajas">Lugar Recepcion Cajas</label></td>
			<td><input type="text" size="65" name="lugarRecepcionCajas" id="lugarRecepcionCajas"></input></td>
		</tr>
	
	<tr>
			<td colspan="2" align="right"><input type="submit" value="Create"/></td>
		</tr>
	</table>
</form>

<% }else{ %>

Utiliza tu cuenta Google.

<% } %>
</div>
</body>
</html>